﻿using System;

namespace SimpleLibraryClasses
{
    public enum ItemStatus
    {
        Available,
        OnLoan
    };
    
    [Serializable()]
    public abstract class Item
    {
        public Item()
        {
            ItemStatus = ItemStatus.Available;
        }

        /// <summary>
        /// The unique code that represents this item and all copies of it (such as a shelf code).
        /// </summary>
        public String ItemCode { get; set; }

        /// <summary>
        /// A short string that describes the item.
        /// </summary>
        public abstract String DisplayName { get; }

        /// <summary>
        /// The Library this item belongs to.
        /// </summary>
        public Library HomeLibrary { get; set; }

        /// <summary>
        /// The Member that currently has the item on loan, or null if available.
        /// </summary>
        public Loan CurrentLoan { get; private set; }
        
        /// <summary>
        /// The loan status of this item
        /// </summary>
        public ItemStatus ItemStatus { get; private set; }

        /// <summary>
        /// Lend this item out.
        /// </summary>
        /// <param name="loan">The loan for this item</param>
        public void Borrow(Loan loan)
        {
            this.CurrentLoan = loan;
            this.ItemStatus = ItemStatus.OnLoan;
        }

        /// <summary>
        /// Return this item to the library
        /// </summary>
        /// <param name="library">The library this item is being returned to</param>
        public void Return(Library library)
        {
            this.HomeLibrary = library;
            this.ItemStatus = ItemStatus.Available;
            this.CurrentLoan = null;
        }

        /// <summary>
        /// Tests that the item in question satisfies all contraints
        /// </summary>
        /// <returns>True of the item is valid, false otherwise</returns>
        public abstract bool IsValid();
    }
}
